package com.tjsinfo.tjsoa.system.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.system.bo.ISystemUserBo;
import com.tjsinfo.tjsoa.system.bo.ISystemUserDepartmentBo;
import com.tjsinfo.tjsoa.system.bo.ISystemUserDutyBo;
import com.tjsinfo.tjsoa.system.bo.ISystemUserPostBO;
import com.tjsinfo.tjsoa.system.bo.ITSystemUserRoleGroupBO;
import com.tjsinfo.tjsoa.system.vo.TSystemRolesGroup;
import com.tjsinfo.tjsoa.system.vo.TSystemUser;
import com.tjsinfo.tjsoa.system.vo.TSystemUserDepartment;
import com.tjsinfo.tjsoa.system.vo.TSystemUserDuty;
import com.tjsinfo.tjsoa.system.vo.TSystemUserPost;
import com.tjsinfo.tjsoa.system.vo.TSystemUserRoleGroup;

/**
 * 查询一个用户根据ID
 * @author Administrator
 *
 */
public class SelectUserByIdAction extends Action{
	private ISystemUserBo systemUserBo;
	private ISystemUserDepartmentBo systemUserDepartmentBo;
	private ISystemUserDutyBo systemUserDutyBo;
	private ISystemUserPostBO systemUserPostBO;
	private ITSystemUserRoleGroupBO systemUserRoleGroupBO;
	
	public ISystemUserDepartmentBo getSystemUserDepartmentBo() {
		return systemUserDepartmentBo;
	}

	public void setSystemUserDepartmentBo(
			ISystemUserDepartmentBo systemUserDepartmentBo) {
		this.systemUserDepartmentBo = systemUserDepartmentBo;
	}

	public ISystemUserDutyBo getSystemUserDutyBo() {
		return systemUserDutyBo;
	}

	public void setSystemUserDutyBo(ISystemUserDutyBo systemUserDutyBo) {
		this.systemUserDutyBo = systemUserDutyBo;
	}

	public ISystemUserPostBO getSystemUserPostBO() {
		return systemUserPostBO;
	}

	public void setSystemUserPostBO(ISystemUserPostBO systemUserPostBO) {
		this.systemUserPostBO = systemUserPostBO;
	}

	public ITSystemUserRoleGroupBO getSystemUserRoleGroupBO() {
		return systemUserRoleGroupBO;
	}

	public void setSystemUserRoleGroupBO(
			ITSystemUserRoleGroupBO systemUserRoleGroupBO) {
		this.systemUserRoleGroupBO = systemUserRoleGroupBO;
	}

	public ISystemUserBo getSystemUserBo() {
		return systemUserBo;
	}

	public void setSystemUserBo(ISystemUserBo systemUserBo) {
		this.systemUserBo = systemUserBo;
	}

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		Integer id = Integer.parseInt(request.getParameter("id")); 
		Integer start = Integer.parseInt(request.getParameter("start"));
		String systemUserDepartmentname = "",systemUserDutyname = "", systemUserPostname="",systemUserRoleGroupname="",
		systemUserDepartmentid = "",systemUserDutyid = "", systemUserPostid="",systemUserRoleGroupid="";
		TSystemUser systemUser = systemUserBo.findByIdSystemUser(id);
	    String email =	systemUser.getEmail()==null?"":systemUser.getEmail();
		systemUser.setEmail(email);	
		List<TSystemUserDepartment> systemUserDepartmentlist = systemUserDepartmentBo.selectByUserId(id);
		List<TSystemUserDuty> systemUserDutylist = systemUserDutyBo.selectByUserId(id);
		List<TSystemUserPost> systemUserPostlist = systemUserPostBO.selectByUserId(id);
		List<TSystemUserRoleGroup> systemUserRoleGrouplist = systemUserRoleGroupBO.selectUserRoleGroupByUserId(id);
		for (TSystemUserDepartment systemUserDepartment : systemUserDepartmentlist) {
			systemUserDepartmentname +=systemUserDepartment.getDepartmentName()+",";
			systemUserDepartmentid +=systemUserDepartment.getDepartmentId()+",";
		}
		for (TSystemUserDuty systemUserDuty : systemUserDutylist) {
			systemUserDutyname +=systemUserDuty.getDutyName()+",";
			systemUserDutyid +=systemUserDuty.getDutyId()+",";
		}
		for (TSystemUserPost systemUserPost : systemUserPostlist) {
			systemUserPostname +=systemUserPost.getPostName()+",";
			systemUserPostid +=systemUserPost.getPostId()+",";
		}
		for (TSystemUserRoleGroup systemUserRoleGroup : systemUserRoleGrouplist) {
			systemUserRoleGroupname += systemUserRoleGroup.getRoleName()+",";
			systemUserRoleGroupid += systemUserRoleGroup.getRoleGroupId()+",";
		}
		if (systemUser.getDataBaseId() != null && systemUser.getSubUserId() != null) {
			String username  = systemUserBo.findByIdSystemUserErJiGongSi(systemUser.getDataBaseId(), systemUser.getSubUserId()).getLoginName();
			systemUser.setSubUserName(username); 
		}else{
			systemUser.setSubUserName("");
			systemUser.setDataBaseId(0);
		}
		
		
		
		
		request.setAttribute("systemUser", systemUser);
		request.setAttribute("start", start);
		request.setAttribute("systemUserDepartmentname", systemUserDepartmentname);
		request.setAttribute("systemUserDutyname", systemUserDutyname);
		request.setAttribute("systemUserPostname", systemUserPostname);
		request.setAttribute("systemUserRoleGroupname", systemUserRoleGroupname);
		request.setAttribute("systemUserDepartmentid", systemUserDepartmentid);
		request.setAttribute("systemUserDutyid", systemUserDutyid);
		request.setAttribute("systemUserPostid", systemUserPostid);
		request.setAttribute("systemUserRoleGroupid", systemUserRoleGroupid);
		return  mapping.findForward("success");
	}
	
	
}
